package komunikacja;


import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.swing.table.AbstractTableModel;


/**
 * 
 * Model tabeli w ktorej bedzie wyswietlana baza danych
 *
 */
class Model extends AbstractTableModel {
	
       private ResultSetMetaData resmd;
       private ResultSet result = null;
       
	
   
        public Model(ResultSet aResultSet){
                result = aResultSet;
                try{
                    resmd = result.getMetaData();
                }
                catch(SQLException e){
                    e.printStackTrace();
                }
        }
 
        public String getColumnName(int c){
                try{
                    return resmd.getColumnName(c+1);
                }
                catch(SQLException e){
                    e.printStackTrace();
                    return "";
                }
        }
 
        public int getColumnCount(){
                try{
                    return resmd.getColumnCount();
                }
                catch(SQLException e){
                    e.printStackTrace();
                    return 0;
                }
        }
        
        public int getRowCount() {
			try {
				result.last();
				return result.getRow();
				
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return 0;
		}
 
        public Object getValueAt(int r, int c){
                try{
                    result.absolute(r+1);
                    return result.getObject(c+1);
                }
                catch(SQLException e){
                    e.printStackTrace();
                    return null;
                }
        }       
       
    	
}

		
		
        



